package model;

import javax.persistence.*;

@NamedQueries({
        @NamedQuery(
                name = "PhoneNumber.getAll",
                query = "SELECT p FROM PhoneNumber p"
        ),
        @NamedQuery(
                name = "PhoneNumber.getByPerson",
                query = "SELECT p FROM PhoneNumber  p WHERE p.person =:person"
        )
})
@Entity
public class PhoneNumber {
    private long id;
    private String code;
    private String number;
    private Person person;

    public PhoneNumber() {
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    @ManyToOne
    public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof PhoneNumber)) return false;

        PhoneNumber number1 = (PhoneNumber) o;

        if (!code.equals(number1.code)) return false;
        if (!number.equals(number1.number)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = code.hashCode();
        result = 31 * result + number.hashCode();
        return result;
    }
}
